﻿Imports System.Data.OleDb
Imports System.Data.OracleClient
Imports System.IO
Imports ccapps.persistent.FinancialTransaction

Public Class FinancialOverviewDeposits
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        If Session("user") = "" Or Session("user") Is Nothing Then
            ' Response.Redirect("../../login.aspx")
            Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()
        End If
        
    End Sub


    Protected Sub BtnCustcode_Click(sender As Object, e As EventArgs) Handles BtnCustcode.Click
        Try
            TxtMsisdn.Text = ""
            ErrorMes.Text = ""
            TxtCoid.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""
            If TxtCustcode.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('CustCode Alanın Girilmesi Zorunludur.');</script>")
            Else
                Dim dt As DataTable = getcustomerInfoFromCustcode(TxtCustcode.Text)
                If dt.Rows.Count > 0 Then
                    Table2.Visible = True
                    LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                    LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblCsid.Text = dt.Rows(0)("CSID").ToString()
                    Dim now As DateTime = DateTime.Now
                    txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                    Dim gun As String = ""
                    Dim gun2 As String = ""

                    If now.Month().ToString().Length = 1 Then
                        gun = "0" + now.Month().ToString()
                    Else
                        gun = now.Month().ToString()
                    End If

                    If now.Day().ToString().Length = 1 Then
                        gun2 = "0" + now.Day().ToString()
                    Else
                        gun2 = now.Day().ToString()
                    End If

                    txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()

                Else
                    ErrorMes.Text = "Girmiş Olduğunuz CUSTCODE'a Ait Veri Bulunamamıştır"

                End If


            End If


        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try

    End Sub

    Protected Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click

        Try
            TblShowDetail.Visible = True
            TblShowDetail2.Visible = False


            Dim bilgiler() As String = txtDate.Text.Split("/")
            Label26.Text = ""
            For Each satir As String In bilgiler
                Label26.Text += satir
            Next



            Dim bilgiler2() As String = txtDate2.Text.Split("/")
            Label27.Text = ""
            For Each satir2 As String In bilgiler2
                Label27.Text += satir2
            Next

            Dim pin_valid_status As Integer = 2
            If txtDate.Text = "" Then
                pin_valid_status = 1
            End If

            Dim dt As DataTable = FinancialTransactionDetails(Label26.Text, Label27.Text, Convert.ToInt32(LblCsid.Text), pin_valid_status)


            'For i As Integer = 1 To 10
            '    Response.Write(dt.Rows(i)(0).ToString)
            'Next

            DtFinancialTransactionDetails.DataSource = dt
            'DtFinancialTransactionDetails.AllowPaging = True
            DtFinancialTransactionDetails.DataBind()

            'Dim dt As DataTable = FinancialDocCustInfo()
            'DataGrid1.DataSource = dt
            'DataGrid1.DataBind()

        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try
        



    End Sub



    Protected Sub DtFinancialTransactionDetails_ItemCommand(source As Object, e As DataGridCommandEventArgs) Handles DtFinancialTransactionDetails.ItemCommand
        'Dim currentPageIndex = Me.DG_OCCTable.CurrentPageIndex

        Try

            If e.CommandName = "view" Then
                TblShowDetail2.Visible = True
                'Response.Write(e.Item.Cells(9).Text)

                Dim dt As DataTable = FinancialTranDetailsExtInfo(Convert.ToInt32(e.Item.Cells(10).Text))
                If dt.Rows.Count > 0 Then
                    LblType.Text = LabelKontrol(dt.Rows(0)("TYPE").ToString())
                    LblRefCode.Text = LabelKontrol(dt.Rows(0)("REFCODE").ToString())
                    LblDocNo.Text = LabelKontrol(dt.Rows(0)("DOCNO").ToString())
                    LblEntryDate.Text = LabelKontrol(String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("ENTYDATE"))))
                    LblBatch.Text = LabelKontrol(dt.Rows(0)("BATCHGENNO").ToString())
                    LblPaymentMode.Text = LabelKontrol(dt.Rows(0)("PAYMODE").ToString())
                    LblAccount.Text = LabelKontrol(dt.Rows(0)("ACCOUNT").ToString())
                    LblAmount2.Text = LabelKontrol(dt.Rows(0)("AMOUNT").ToString())
                    LblGlAcc.Text = LabelKontrol(dt.Rows(0)("GLACCOUNT").ToString())
                    LblPost.Text = LabelKontrol(dt.Rows(0)("POSTDATE").ToString())
                    LblComment.Text = LabelKontrol(dt.Rows(0)("COMMENT").ToString())
                    LblTransNo.Text = LabelKontrol(dt.Rows(0)("TRANSNO").ToString())
                    LblRefNo.Text = LabelKontrol(String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("REFDATE"))))
                    LblEffective.Text = LabelKontrol(String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("EFFECTIVEDATE"))))
                    LblCreatedBy.Text = LabelKontrol(dt.Rows(0)("CREATEDBY").ToString())
                    LblBankName.Text = LabelKontrol(dt.Rows(0)("BANKNAME").ToString())
                    LblSubAcc.Text = LabelKontrol(dt.Rows(0)("ACCOUNT").ToString())
                    LblGranted.Text = LabelKontrol(dt.Rows(0)("GRANTEDDIS").ToString())
                    'LblGranted.Text = dt.Rows(0)("GRANTEDDIS").ToString()
                    LblGlAccount.Text = LabelKontrol(dt.Rows(0)("GLACCOUNT").ToString())

                End If
                Dim dt2 As DataTable = FinancialTranDetailsGridBound(Convert.ToInt32(e.Item.Cells(10).Text))
                DataGrid2.DataSource = dt2
                DataGrid2.DataBind()
            End If

        Catch ex As Exception


            Session("message") = ex.Message
            Response.Clear()
            Response.Status = "302 Object Moved"
            Response.RedirectLocation = "CX_Exception.aspx"
            Response.End()




        End Try
    End Sub
    Public Shared Function LabelKontrol(Lbl As String) As String
        If Lbl = "" Then
            Return "--"
        Else
            Return Lbl

        End If


    End Function


    Protected Sub BtnCoid_Click(sender As Object, e As EventArgs) Handles BtnCoid.Click

        Try
            TxtMsisdn.Text = ""
            ErrorMes.Text = ""
            TxtCustcode.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""

            If TxtCoid.Text = "" Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('COID Alanın Girilmesi Zorunludur.');</script>")
            Else
                Dim dt As DataTable = getcustomerInfoFromCOID(TxtCoid.Text)
                If dt.Rows.Count > 0 Then
                    Table2.Visible = True
                    LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                    LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                    LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                    LblCsid.Text = dt.Rows(0)("CSID").ToString()
                    Dim now As DateTime = DateTime.Now
                    txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                    Dim gun As String = ""
                    Dim gun2 As String = ""

                    If now.Month().ToString().Length = 1 Then
                        gun = "0" + now.Month().ToString()
                    Else
                        gun = now.Month().ToString()
                    End If

                    If now.Day().ToString().Length = 1 Then
                        gun2 = "0" + now.Day().ToString()
                    Else
                        gun2 = now.Day().ToString()
                    End If

                    txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()

                Else
                    ErrorMes.Text = "Girmiş Olduğunuz COID'ye Ait Veri Bulunamamıştır"

                End If


            End If


        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try


    End Sub

    Protected Sub BtnMsisdn_Click(sender As Object, e As EventArgs) Handles BtnMsisdn.Click
        Try
            TxtCustcode.Text = ""
            ErrorMes.Text = ""
            TxtCoid.Text = ""
            LblCustomer.Text = ""
            LblCurBalance.Text = ""
            LblTotal1.Text = ""
            LblPrevBalance2.Text = ""
            LblLastBillOn.Text = ""
            LblUnBill.Text = ""
            If Not TxtMsisdn.Text.Length = 10 Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanı 10 Karakter İçermelidir.');</script>")
            Else
                If TxtMsisdn.Text = "" Then
                    Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('MSISDN Alanın Girilmesi Zorunludur.');</script>")
                Else
                    Dim dt As DataTable = getcustomerInfoFromMSISDN(TxtMsisdn.Text)
                    If dt.Rows.Count > 0 Then
                        Table2.Visible = True
                        LblCustomer.Text = dt.Rows(0)("NAME").ToString() + "   " + dt.Rows(0)("LASTNAME").ToString() + "   " + dt.Rows(0)("CITY").ToString()
                        LblCurBalance.Text = dt.Rows(0)("CURBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblUnBill.Text = dt.Rows(0)("UNBILL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblTotal1.Text = dt.Rows(0)("TOTAL").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblLastBillOn.Text = String.Format("{0:d}", Convert.ToDateTime(dt.Rows(0)("LAST_BILLED_DATE")))
                        LblPrevBalance2.Text = dt.Rows(0)("PREVBALANCE").ToString() + " " + dt.Rows(0)("MONEY").ToString()
                        LblCsid.Text = dt.Rows(0)("CSID").ToString()
                        Dim now As DateTime = DateTime.Now
                        txtDate.Text = "12/12/" + (now.Year() - 1).ToString()
                        Dim gun As String = ""
                        Dim gun2 As String = ""

                        If now.Month().ToString().Length = 1 Then
                            gun = "0" + now.Month().ToString()
                        Else
                            gun = now.Month().ToString()
                        End If

                        If now.Day().ToString().Length = 1 Then
                            gun2 = "0" + now.Day().ToString()
                        Else
                            gun2 = now.Day().ToString()
                        End If

                        txtDate2.Text = gun2 + "/" + gun + "/" + now.Year().ToString()

                    Else
                        ErrorMes.Text = "Girmiş Olduğunuz MSISDN'e Ait Veri Bulunamamıştır"

                    End If
                End If
            End If



        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try






    End Sub

    
    Protected Sub DG_CustomerFinPage(source As Object, e As DataGridPageChangedEventArgs) Handles DtFinancialTransactionDetails.PageIndexChanged
        Me.GetDisplayCustomerFinDoc(e.NewPageIndex)
    End Sub

  

    Private Sub GetDisplayCustomerFinDoc(ByVal currentPageIndex As Integer)
        Try
            TblShowDetail.Visible = True



            Dim bilgiler() As String = txtDate.Text.Split("/")
            Label26.Text = ""
            For Each satir As String In bilgiler
                Label26.Text += satir
            Next



            Dim bilgiler2() As String = txtDate2.Text.Split("/")
            Label27.Text = ""
            For Each satir2 As String In bilgiler2
                Label27.Text += satir2
            Next

            Dim pin_valid_status As Integer = 2
            If txtDate.Text = "" Then
                pin_valid_status = 1
            End If

            Dim dt As DataTable = FinancialTransactionDetails(Label26.Text, Label27.Text, Convert.ToInt32(LblCsid.Text), pin_valid_status)


            DtFinancialTransactionDetails.DataSource = dt
            Me.DtFinancialTransactionDetails.CurrentPageIndex = currentPageIndex
            Me.DtFinancialTransactionDetails.AllowPaging = True
            DtFinancialTransactionDetails.DataBind()

        Catch ex As Exception
            ErrorMes.Text = "İşlem gerçekleşmemiştir lütfen tekrar deneyiniz."
        End Try
        
     


    End Sub

   

End Class